package com.esri.core.geometry;

import com.esri.core.geometry.Geometry;

/* loaded from: classes.dex */
class PolygonUtils {

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes.dex */
    public enum PiPResult {
        PiPOutside,
        PiPInside,
        PiPBoundary
    }

    PolygonUtils() {
    }

    public static PiPResult isPointInPolygon2D(Polygon polygon, Point point, double d) {
        int isPointInPolygon = PointInPolygonHelper.isPointInPolygon(polygon, point, d);
        if (isPointInPolygon == 0) {
            return PiPResult.PiPOutside;
        }
        if (isPointInPolygon == 1) {
            return PiPResult.PiPInside;
        }
        return PiPResult.PiPBoundary;
    }

    public static PiPResult isPointInPolygon2D(Polygon polygon, Point2D point2D, double d) {
        int isPointInPolygon = PointInPolygonHelper.isPointInPolygon(polygon, point2D, d);
        if (isPointInPolygon == 0) {
            return PiPResult.PiPOutside;
        }
        if (isPointInPolygon == 1) {
            return PiPResult.PiPInside;
        }
        return PiPResult.PiPBoundary;
    }

    static PiPResult a(Polygon polygon, double d, double d2, double d3) {
        int a = PointInPolygonHelper.a(polygon, d, d2, d3);
        if (a == 0) {
            return PiPResult.PiPOutside;
        }
        if (a == 1) {
            return PiPResult.PiPInside;
        }
        return PiPResult.PiPBoundary;
    }

    public static PiPResult isPointInRing2D(Polygon polygon, int i, Point2D point2D, double d) {
        int isPointInRing = PointInPolygonHelper.isPointInRing((MultiPathImpl) polygon._getImpl(), i, point2D, d);
        if (isPointInRing == 0) {
            return PiPResult.PiPOutside;
        }
        if (isPointInRing == 1) {
            return PiPResult.PiPInside;
        }
        return PiPResult.PiPInside;
    }

    public static PiPResult isPointInAnyOuterRing(Polygon polygon, Point2D point2D, double d) {
        int isPointInAnyOuterRing = PointInPolygonHelper.isPointInAnyOuterRing(polygon, point2D, d);
        if (isPointInAnyOuterRing == 0) {
            return PiPResult.PiPOutside;
        }
        if (isPointInAnyOuterRing == 1) {
            return PiPResult.PiPInside;
        }
        return PiPResult.PiPInside;
    }

    public static void testPointsInPolygon2D(Polygon polygon, Point2D[] point2DArr, int i, double d, PiPResult[] piPResultArr) {
        if (point2DArr.length < i || piPResultArr.length < i) {
            throw new IllegalArgumentException();
        }
        for (int i2 = 0; i2 < i; i2++) {
            piPResultArr[i2] = isPointInPolygon2D(polygon, point2DArr[i2], d);
        }
    }

    static void a(Polygon polygon, double[] dArr, int i, double d, PiPResult[] piPResultArr) {
        if (dArr.length / 2 < i || piPResultArr.length < i) {
            throw new IllegalArgumentException();
        }
        for (int i2 = 0; i2 < i; i2++) {
            int i3 = i2 * 2;
            piPResultArr[i2] = a(polygon, dArr[i3], dArr[i3 + 1], d);
        }
    }

    public static void testPointsInArea2D(Geometry geometry, Point2D[] point2DArr, int i, double d, PiPResult[] piPResultArr) {
        if (geometry.getType() == Geometry.Type.POLYGON) {
            testPointsInPolygon2D((Polygon) geometry, point2DArr, i, d, piPResultArr);
        } else if (geometry.getType() == Geometry.Type.ENVELOPE) {
            Envelope2D envelope2D = new Envelope2D();
            ((Envelope) geometry).queryEnvelope2D(envelope2D);
            a(envelope2D, point2DArr, i, d, piPResultArr);
        } else {
            throw new GeometryException("invalid_call");
        }
    }

    public static void testPointsInArea2D(Geometry geometry, double[] dArr, int i, double d, PiPResult[] piPResultArr) {
        if (geometry.getType() == Geometry.Type.POLYGON) {
            a((Polygon) geometry, dArr, i, d, piPResultArr);
        } else if (geometry.getType() == Geometry.Type.ENVELOPE) {
            Envelope2D envelope2D = new Envelope2D();
            ((Envelope) geometry).queryEnvelope2D(envelope2D);
            a(envelope2D, dArr, i, d, piPResultArr);
        } else {
            throw new GeometryException("invalid_call");
        }
    }

    static boolean a(MultiPathImpl multiPathImpl, int i, int i2, double d) {
        SegmentIteratorImpl querySegmentIterator = multiPathImpl.querySegmentIterator();
        querySegmentIterator.resetToPath(i);
        if (!querySegmentIterator.nextPath() || !querySegmentIterator.hasNextSegment()) {
            throw new GeometryException("corrupted geometry");
        }
        int i3 = 2;
        while (i3 == 2 && querySegmentIterator.hasNextSegment()) {
            i3 = PointInPolygonHelper.isPointInRing(multiPathImpl, i2, querySegmentIterator.nextSegment().d(0.5d), d);
        }
        if (i3 != 2) {
            return i3 == 1;
        }
        throw new GeometryException("internal error");
    }

    private static void a(Envelope2D envelope2D, Point2D[] point2DArr, int i, double d, PiPResult[] piPResultArr) {
        if (point2DArr.length < i || piPResultArr.length < i) {
            throw new IllegalArgumentException();
        }
        int i2 = 0;
        if (envelope2D.isEmpty()) {
            while (i2 < i) {
                piPResultArr[i2] = PiPResult.PiPOutside;
                i2++;
            }
            return;
        }
        double d2 = (-d) * 0.5d;
        envelope2D.inflate(d2, d2);
        double d3 = d * 0.5d;
        envelope2D.inflate(d3, d3);
        while (i2 < i) {
            if (envelope2D.contains(point2DArr[i2])) {
                piPResultArr[i2] = PiPResult.PiPInside;
            } else if (!envelope2D.contains(point2DArr[i2])) {
                piPResultArr[i2] = PiPResult.PiPOutside;
            } else {
                piPResultArr[i2] = PiPResult.PiPBoundary;
            }
            i2++;
        }
    }

    private static void a(Envelope2D envelope2D, double[] dArr, int i, double d, PiPResult[] piPResultArr) {
        if (dArr.length / 2 < i || piPResultArr.length < i) {
            throw new IllegalArgumentException();
        }
        int i2 = 0;
        if (envelope2D.isEmpty()) {
            while (i2 < i) {
                piPResultArr[i2] = PiPResult.PiPOutside;
                i2++;
            }
            return;
        }
        double d2 = (-d) * 0.5d;
        envelope2D.inflate(d2, d2);
        double d3 = d * 0.5d;
        envelope2D.inflate(d3, d3);
        while (i2 < i) {
            int i3 = i2 * 2;
            int i4 = i3 + 1;
            if (envelope2D.contains(dArr[i3], dArr[i4])) {
                piPResultArr[i2] = PiPResult.PiPInside;
            } else if (!envelope2D.contains(dArr[i3], dArr[i4])) {
                piPResultArr[i2] = PiPResult.PiPOutside;
            } else {
                piPResultArr[i2] = PiPResult.PiPBoundary;
            }
            i2++;
        }
    }
}
